#ifndef CONSTANTS_H
#define CONSTANTS_H

#include <QString>
#include <QStringList>

/**
 * @brief 餐厅点餐系统常量定义
 * 
 * 包含系统中使用的所有常量定义，便于维护和配置
 */

namespace RestaurantSystem {
namespace Constants {

// ============================================================================
// 应用程序信息
// ============================================================================
const QString APP_NAME = "餐厅点餐系统";
const QString APP_VERSION = "1.0.0";
const QString APP_ORGANIZATION = "RestaurantSystem";
const QString APP_DOMAIN = "restaurant.system";

// ============================================================================
// 文件路径常量
// ============================================================================
// 动态获取数据目录路径的函数声明
QString getDataDirectory();
QString getBackupDirectory();
QString getResourcesDirectory();

// 基础目录名（相对路径）
const QString DATA_DIR_NAME = "data";
const QString BACKUP_DIR_NAME = "backup";
const QString RESOURCES_DIR_NAME = "resources";
const QString IMAGES_DIR_NAME = "images";
const QString ICONS_DIR_NAME = "icons";

// 数据文件名
const QString USERS_FILE = "users.json";
const QString MENU_FILE = "menu.json";
const QString ORDERS_FILE = "orders.json";
const QString RATINGS_FILE = "ratings.json";
const QString CONFIG_FILE = "config.json";

// 动态获取完整文件路径的函数声明
QString getUsersFilePath();
QString getMenuFilePath();
QString getOrdersFilePath();
QString getRatingsFilePath();
QString getConfigFilePath();

// ============================================================================
// 业务规则常量
// ============================================================================

// 用户相关
const int MIN_USERNAME_LENGTH = 3;
const int MAX_USERNAME_LENGTH = 20;
const int MIN_PASSWORD_LENGTH = 6;
const int MAX_PASSWORD_LENGTH = 50;
const QString PASSWORD_REGEX = "^[a-zA-Z0-9@#$%^&+=]{6,}$"; // 密码格式：至少6位，字母数字和特殊字符

// 菜品相关
const int MIN_MENU_NAME_LENGTH = 1;
const int MAX_MENU_NAME_LENGTH = 50;
const int MAX_DESCRIPTION_LENGTH = 500;
const double MIN_PRICE = 0.01;
const double MAX_PRICE = 9999.99;
const int MIN_STOCK = 0;
const int MAX_STOCK = 99999;
const int LOW_STOCK_THRESHOLD = 5;

// 订单相关
const int MIN_ORDER_QUANTITY = 1;
const int MAX_ORDER_QUANTITY = 99;
const int MAX_ORDER_ITEMS = 50;
const double MAX_ORDER_TOTAL = 99999.99;

// 评分相关
const int MIN_RATING = 1;
const int MAX_RATING = 5;
const int MAX_COMMENT_LENGTH = 500;

// ============================================================================
// 界面常量
// ============================================================================

// 窗口尺寸
const int MAIN_WINDOW_MIN_WIDTH = 1024;
const int MAIN_WINDOW_MIN_HEIGHT = 768;
const int LOGIN_DIALOG_WIDTH = 400;
const int LOGIN_DIALOG_HEIGHT = 300;

// 表格列宽
const int TABLE_ID_COLUMN_WIDTH = 120;
const int TABLE_NAME_COLUMN_WIDTH = 150;
const int TABLE_PRICE_COLUMN_WIDTH = 80;
const int TABLE_STOCK_COLUMN_WIDTH = 80;
const int TABLE_STATUS_COLUMN_WIDTH = 100;
const int TABLE_DATE_COLUMN_WIDTH = 120;

// 字体大小
const int TITLE_FONT_SIZE = 16;
const int NORMAL_FONT_SIZE = 12;
const int SMALL_FONT_SIZE = 10;

// 间距
const int WIDGET_MARGIN = 10;
const int WIDGET_SPACING = 5;
const int BUTTON_HEIGHT = 30;
const int INPUT_HEIGHT = 25;

// ============================================================================
// 系统设置常量
// ============================================================================

// 性能相关
const int UI_REFRESH_INTERVAL = 100;     // UI刷新间隔(毫秒)
const int DATA_SAVE_INTERVAL = 5000;     // 数据保存间隔(毫秒)
const int MAX_CACHE_SIZE = 1000;         // 最大缓存条目数
const int FILE_LOCK_TIMEOUT = 3000;      // 文件锁超时时间(毫秒)

// 备份相关
const int MAX_BACKUP_FILES = 10;         // 最大备份文件数
const QString BACKUP_DATE_FORMAT = "yyyyMMdd_hhmmss";

// 日志相关
const QString LOG_DATE_FORMAT = "yyyy-MM-dd hh:mm:ss";
const int MAX_LOG_FILE_SIZE = 10 * 1024 * 1024; // 10MB

// ============================================================================
// 菜品分类常量
// ============================================================================
const QStringList DEFAULT_CATEGORIES = {
    "主食",
    "饮品", 
    "小菜",
    "汤品",
    "甜品",
    "凉菜",
    "热菜"
};

// ============================================================================
// 支付方式常量
// ============================================================================
const QStringList PAYMENT_METHODS = {
    "现金支付",
    "银行卡支付",
    "微信支付",
    "支付宝支付",
    "其他"
};

// ============================================================================
// 订单状态常量
// ============================================================================
const QStringList ORDER_STATUS_LIST = {
    "待处理",
    "制作中", 
    "已完成",
    "已取消"
};

// ============================================================================
// 错误消息常量
// ============================================================================
namespace ErrorMessages {
    const QString GENERIC_ERROR = "操作失败，请稍后重试";
    const QString NETWORK_ERROR = "网络连接失败";
    const QString FILE_NOT_FOUND = "文件不存在";
    const QString FILE_READ_ERROR = "文件读取失败";
    const QString FILE_WRITE_ERROR = "文件写入失败";
    const QString PERMISSION_DENIED = "权限不足";
    const QString INVALID_INPUT = "输入数据无效";
    const QString DATA_CORRUPTED = "数据文件已损坏";
    
    // 用户相关错误
    const QString USER_NOT_FOUND = "用户不存在";
    const QString USER_ALREADY_EXISTS = "用户名已存在";
    const QString INVALID_PASSWORD = "密码错误";
    const QString PASSWORD_TOO_WEAK = "密码强度不足";
    
    // 菜品相关错误  
    const QString MENU_ITEM_NOT_FOUND = "菜品不存在";
    const QString INSUFFICIENT_STOCK = "库存不足";
    const QString INVALID_PRICE = "价格无效";
    
    // 订单相关错误
    const QString ORDER_NOT_FOUND = "订单不存在";
    const QString ORDER_CANNOT_CANCEL = "订单无法取消";
    const QString ORDER_ALREADY_COMPLETED = "订单已完成";
    const QString EMPTY_ORDER = "订单不能为空";
}

// ============================================================================
// 成功消息常量
// ============================================================================
namespace SuccessMessages {
    const QString OPERATION_SUCCESS = "操作成功";
    const QString SAVE_SUCCESS = "保存成功";
    const QString DELETE_SUCCESS = "删除成功";
    const QString UPDATE_SUCCESS = "更新成功";
    
    const QString USER_REGISTERED = "用户注册成功";
    const QString USER_LOGIN = "登录成功";
    const QString PASSWORD_CHANGED = "密码修改成功";
    
    const QString MENU_ITEM_ADDED = "菜品添加成功";
    const QString MENU_ITEM_UPDATED = "菜品更新成功";
    const QString MENU_ITEM_DELETED = "菜品删除成功";
    
    const QString ORDER_CREATED = "订单创建成功";
    const QString ORDER_UPDATED = "订单状态更新成功";
    const QString ORDER_CANCELLED = "订单取消成功";
    
    const QString PAYMENT_SUCCESS = "支付成功";
    const QString RATING_SUBMITTED = "评分提交成功";
}

// ============================================================================
// 提示消息常量
// ============================================================================
namespace InfoMessages {
    const QString CONFIRM_DELETE = "确认删除该项目？";
    const QString CONFIRM_CANCEL_ORDER = "确认取消该订单？";
    const QString UNSAVED_CHANGES = "有未保存的更改，是否保存？";
    const QString LOW_STOCK_WARNING = "库存不足，请及时补货";
    const QString BACKUP_CREATED = "数据备份已创建";
    const QString DATA_LOADING = "正在加载数据...";
    const QString DATA_SAVING = "正在保存数据...";
}

} // namespace Constants
} // namespace RestaurantSystem

#endif // CONSTANTS_H
